home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / actlib11.zip / CALC.ZIP / SIMPLIFY.C < prev    next >
C/C++ Source or Header  |  1993-01-14  |  536b  |  31 lines

  1. /*
  2.  *  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be) 
  3.  *
  4.  *  SIMPLIFY
  5.  *
  6.  *  Topic :             Suppress trailing '0' of a string number
  7.  *
  8.  */
  9.  
  10.  
  11. #include "calc.h"
  12.  
  13.  
  14.  
  15. char *simplify( char *number )
  16.  
  17. { char point = 0 ;
  18.   char *ptr1 , *ptr2 ;
  19.  
  20.   for ( ptr1 = ptr2 = number ; *ptr1 ; ptr1 ++ )
  21.       {
  22.         if ( *ptr1 != '0' ) ptr2 = ptr1 ;
  23.         if ( *ptr1 == '.' ) point = 1 ;
  24.       }
  25.  
  26.   if ( point ) *(ptr2 + 1) = '\0' ;
  27.   if ( *ptr2 == '.' ) *ptr2 = '\0' ;
  28.  
  29.   return number ;
  30. }
  31.